package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
/**本类用于引入封装的代码，最终实现效果*/
public class Demo04 {
    public static void main(String[] args) throws Exception {
        //利用工具类  1,注册驱动 2,获取连接
        Connection c = Demo03.JDBCutils.get();
        System.out.println("请输入账号");
        String a= new Scanner(System.in).next();
        System.out.println("请输入密码");
        String b= new Scanner(System.in).next();
        //SQL骨架，? :占位符
        String sql = "select * from user where name = ? and pwd = ?";
        //获取传输器
        PreparedStatement s = c.prepareStatement(sql);
        //给 ? 赋值
        s.setObject(1,a);
        s.setObject(2,b);
        //执行SQL语句
        ResultSet r = s.executeQuery();
        if (r.next()){
            System.out.println("欢迎回来");
        }else {
            System.out.println("登录失败");
        }
        r.close();
        s.close();
        c.close();


    }
}
